package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.goods.MallRechargeConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MallRechargeConfigDaoImpl extends TempDao {

    public Map<Integer, MallRechargeConfig> getMallRechargeMap() {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_p_mall_recharge";
        Map<Integer, MallRechargeConfig> dataMap = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                MallRechargeConfig data = new MallRechargeConfig();
                data.setId(rs.getInt("id"));
                data.setPrice(rs.getLong("price"));
                data.setParam(rs.getString("param"));
                data.setReturnIngots(rs.getLong("returnIngots"));
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
